﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PF;

namespace pufflesweb.user
{
    public partial class shopping_add : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            PModel.User mysuer = new PModel.User();

            mysuer = (PModel.User)PF.SessionHelper.GetSession("user");



            if (mysuer != null)
            {
                PModel.Shopping shopping = new PModel.Shopping();//购物车空对象

                int gid = int.Parse(Request.QueryString["gid"].ToString());//获取上个页面商品的GID

                PModel.Goods goods = PBLL.Goods.Getgoods(gid);

                shopping.Goods = goods;
                shopping.User = mysuer;
                shopping.Snumber = 1;
                shopping.Sstate = 0;

                //if (PBLL.Shopping.list(goods.GID, mysuer.UID, 0).Count > 0){}
                

                if (PBLL.Shopping.add(shopping))
                {
                    PF.JsHelper.AlertAndRedirect("加入购物车成功！", "../shop-list.aspx");
                }
                else
                {
                    PF.JsHelper.AlertAndRedirect("加入购物车失败", "../shop-list.aspx");
                }
            }
            else
            {
                PF.JsHelper.AlertAndRedirect("尚未登录！", "../shop-list.aspx");
            }
        }
    }
}